<template>
  <div class="mod-clcHousePersonInfo__clchousepersoninfo">
    <back-icon></back-icon>
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-button @click="state.getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="danger" @click="state.deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="houseNum" label="门牌号" header-align="center" align="center"></el-table-column>
      <el-table-column prop="realName" label="姓名" header-align="center" align="center"></el-table-column>
      <el-table-column prop="sex" :label="$t('user.gender')" sortable="custom" header-align="center" align="center">
        <template v-slot="scope">
          {{ state.getDictLabel("gender", scope.row.sex) }}
        </template>
      </el-table-column>

      <el-table-column prop="personType" label="人员类型" header-align="center" align="center">
        <template v-slot="scope">
          <div v-if="scope.row.personType=='0'">住户</div>
          <div v-if="scope.row.personType=='1'">租户</div>
        </template>
      </el-table-column>
      <el-table-column prop="isMaster" label="是否户主(承租人)" width="200" header-align="center" align="center">
        <template v-slot="scope">
          <div v-if="scope.row.isMaster=='0'">否</div>
          <div v-if="scope.row.isMaster=='1'">是</div>
        </template>
      </el-table-column>
      <el-table-column prop="relationship" label="与户主关系" header-align="center" align="center"></el-table-column>
      <el-table-column prop="mobile" label="电话" header-align="center" align="center"></el-table-column>
      <el-table-column prop="vehicleType" label="车辆类型" header-align="center" align="center">
        <template v-slot="scope">
          <div v-if="scope.row.vehicleType=='0'">机动车</div>
          <div v-if="scope.row.vehicleType=='1'">非机动车</div>
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="备注" header-align="center" align="center"></el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button  type="primary" link @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button type="primary" link @click="state.deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update :key="addKey" ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import BackIcon from "@/components/backIcon.vue";
import { nextTick, reactive, ref, toRefs, watch } from "vue";
import AddOrUpdate from "./clchousepersoninfo-add-or-update.vue";
import {useRoute} from "vue-router";
import Template from "@/views/devtools/template.vue";
const { query } = useRoute();

const view = reactive({
  getDataListURL: "/clcHousePersonInfo/clchousepersoninfo/page",
  getDataListIsPage: true,
  exportURL: "/clcHousePersonInfo/clchousepersoninfo/export",
  deleteURL: "/clcHousePersonInfo/clchousepersoninfo",
  deleteIsBatch: true,
  dataForm: {
    houseId: query.locationId,
    houseNum: query.houseNum,
  }
});

const state = reactive({ ...useView(view), ...toRefs(view) });


const addKey = ref(0);
const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addKey.value++;
  nextTick(() => {
    addOrUpdateRef.value.init(id, state.dataForm.houseId, state.dataForm.houseNum);
  });
};
</script>
